#include <QByteArray>
#include <QXmlAttributes>
#include <QXmlStreamReader>
#include <QString>
#include <QDebug>
#include <QDateTime>

#include "hmiinstance.h"
#include "ui_form.h"

HmiInstance::HmiInstance(short Local_Remote){
    LocalRemote = Local_Remote;
    if(LocalRemote == LOCALCONTOLLER){
        this->ui = new Ui::Form;
        this->pLaserSensorData = new ST_LaserSensorData;
        this->mWorkType = ENUM_WorkType::Mannual;
        this->ui->setupUi(this);
        this->UiDataInit();
        this->LaserSensorDataScopeViewInit();
        this->SignalSlotConnect();
    }
    else{

    }
}

HmiInstance::~HmiInstance(){
    if(LocalRemote == LOCALCONTOLLER){

    }
    else{

    }
}


short HmiInstance::getBackendhandle(BackendInterface* p){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface = p;
        return 1;
    }
    else{
        return 0;
    }

}

short HmiInstance::UiDataInit(){
    if(LocalRemote == LOCALCONTOLLER){
        return 1;
    }
    else{
        return 0;
    }
}
short HmiInstance::UiDataUpdate(){
    if(LocalRemote == LOCALCONTOLLER){
         if(this->mWorkType == ENUM_WorkType::Auto){
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::RobotUDPConnect)){ui->RobotUDPConnect->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->RobotUDPConnect->setStyleSheet("color:#34495E;background:#E7E7E7;");}

            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::TaskNull)){ui->TaskNull->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->TaskNull->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::Calibration)){ui->Calibration->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->Calibration->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::SeamFinding)){ui->SeamFinding->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->SeamFinding->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::SeamFindingStart2End)){ui->SeamFindingStart2End->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->SeamFindingStart2End->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::SeamTracking)){ui->SeamTracking->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->SeamTracking->setStyleSheet("color:#34495E;background:#E7E7E7;");}

            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalPos1)){ui->CalPos1->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalPos1->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalPos2)){ui->CalPos2->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalPos2->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalPos3)){ui->CalPos3->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalPos3->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalPos4)){ui->CalPos4->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalPos4->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalPos5)){ui->CalPos5->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalPos5->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalPos6)){ui->CalPos6->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalPos6->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalibrationDo)){ui->CalibrationDo->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalibrationDo->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::CalibrationSave)){ui->CalibrationSave->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->CalibrationSave->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::PointRecord)){ui->PointRecord->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->PointRecord->setStyleSheet("color:#34495E;background:#E7E7E7;");}
            if(this->pbackendinterface->getButtonStatus(ENUM_ButtonName::SeamPosCal)){ui->SeamPosCal->setStyleSheet("color:#2D3E50;background:#B8C6D1;");}else{ui->SeamPosCal->setStyleSheet("color:#34495E;background:#E7E7E7;");}

            double tempvalue[6];

            this->pbackendinterface->readAutoCalibrationResualt(tempvalue);
            ui->H2EX->setValue(tempvalue[0]); ui->H2EY->setValue(tempvalue[1]); ui->H2EZ->setValue(tempvalue[2]);
            ui->H2EA->setValue(tempvalue[3]); ui->H2EB->setValue(tempvalue[4]); ui->H2EC->setValue(tempvalue[5]);

            this->pbackendinterface->readAutoSeamStartPointResualt(tempvalue);
            ui->StartPoxX->setValue(tempvalue[0]); ui->StartPoxY->setValue(tempvalue[1]); ui->StartPoxZ->setValue(tempvalue[2]);
            ui->StartPoxA->setValue(tempvalue[3]); ui->StartPoxB->setValue(tempvalue[4]); ui->StartPoxC->setValue(tempvalue[5]);

            this->pbackendinterface->readAutoSeamEndPointResualt(tempvalue);
            ui->EndPoxX->setValue(tempvalue[0]); ui->EndPoxY->setValue(tempvalue[1]); ui->EndPoxZ->setValue(tempvalue[2]);
            ui->EndPoxA->setValue(tempvalue[3]); ui->EndPoxB->setValue(tempvalue[4]); ui->EndPoxC->setValue(tempvalue[5]);
        }
        return 1;
    }
    else{
        return 0;
    }
}


short HmiInstance::LaserSensorDataScopeViewInit(){
    if(LocalRemote == LOCALCONTOLLER){
        ui->LaserYView->addGraph();
        ui->LaserYView->graph(0)->setPen(QPen(Qt::red));

        ui->LaserZView->addGraph();
        ui->LaserZView->graph(0)->setPen(QPen(Qt::red));

        ui->LaserYView->graph(0)->setAntialiasedFill(true);
        ui->LaserYView->yAxis->setRange(-1,1);
        ui->LaserYView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->LaserYView->xAxis->setDateTimeFormat("s");
        ui->LaserYView->xAxis->setAutoTickStep(false);
        ui->LaserYView->xAxis->setTickStep(2);
        ui->LaserYView->xAxis->setVisible(false);
        ui->LaserYView->axisRect()->setupFullAxesBox();

        ui->LaserZView->graph(0)->setAntialiasedFill(true);
        ui->LaserZView->yAxis->setRange(-1,1);
        ui->LaserZView->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->LaserZView->xAxis->setDateTimeFormat("s");
        ui->LaserZView->xAxis->setAutoTickStep(false);
        ui->LaserZView->xAxis->setTickStep(2);
        ui->LaserZView->xAxis->setVisible(false);
        ui->LaserZView->axisRect()->setupFullAxesBox();
        return 1;
    }
    else{
        return 0;
    }
}

short HmiInstance::LaserSensorDataScopeViewUpdate(){
    if(LocalRemote == LOCALCONTOLLER){

        double key;
        static double lastPointKey1 = 0;

        if(this->pbackendinterface != nullptr){
            this->pbackendinterface->ReadLaserSensorDataY(this->pLaserSensorData->y);
            this->pbackendinterface->ReadLaserSensorDataZ(this->pLaserSensorData->z);
        }

        key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
        if (key-lastPointKey1 > 0.01){
            ui->LaserYView->graph(0)->addData(key, this->pLaserSensorData->y);
            ui->LaserYView->graph(0)->removeDataBefore(key-20);

            ui->LaserZView->graph(0)->addData(key, this->pLaserSensorData->z);
            ui->LaserZView->graph(0)->removeDataBefore(key-20);
            lastPointKey1 = key;
        }

        this->ui->LaserYView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        this->ui->LaserYView->replot();

        this->ui->LaserZView->xAxis->setRange(key+0.25, 20, Qt::AlignRight);
        this->ui->LaserZView->replot();

        return 1;
    }
    else{
        return 0;
    }
}

short HmiInstance::SignalSlotConnect(){
    if(LocalRemote == LOCALCONTOLLER){
        connect(ui->SensorConnect, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSensorConnect()));
        connect(ui->RobotTCPConnect, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedRobotTCPConnect()));
        connect(ui->RobotUDPConnect, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedRobotUDPConnect()));
        connect(ui->Calibration, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalibration()));

        connect(ui->SeamFinding, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSeamFinding()));
        connect(ui->SeamFindingStart2End, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSeamFindingStart2End()));
        connect(ui->SeamTracking, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSeamTracking()));
        connect(ui->CalPos1, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalPos1()));

        connect(ui->CalPos2, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalPos2()));
        connect(ui->CalPos3, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalPos3()));
        connect(ui->CalPos4, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalPos4()));
        connect(ui->CalPos5, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalPos5()));


        connect(ui->CalPos6, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalPos6()));
        connect(ui->CalibrationDo, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalibrationDo()));
        connect(ui->CalibrationSave, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalibrationSave()));

        connect(ui->CalibrationReset, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedCalibrationReset()));
        connect(ui->TaskNull, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedTaskNull()));
        connect(ui->WorkType, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedWorkType()));
        connect(ui->SeamPosCal, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSeamPosCal()));
        connect(ui->SeamPosReset, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSeamPosReset()));
        connect(ui->SeamPosSend, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedSeamPosSend()));
        connect(ui->PointRecord, SIGNAL(clicked(bool)), this, SLOT(onbtnClickedPointRecord()));

        return 1;
    }
    else{
        return 0;
    }

}
void HmiInstance::onbtnClickedSensorConnect(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedSensorConnect();
        ui->SensorConnect->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedRobotTCPConnect(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedRobotTCPConnect();
        ui->RobotTCPConnect->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedRobotUDPConnect(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedRobotUDPConnect();
    }
    else{

    }
}
void HmiInstance::onbtnClickedTaskNull(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedTaskNull();
        ui->TaskNull->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
        ui->Calibration->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFinding->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFindingStart2End->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamTracking->setStyleSheet("color:#34495E;background:#E7E7E7;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalibration(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalibration();
        ui->TaskNull->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->Calibration->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
        ui->SeamFinding->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFindingStart2End->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamTracking->setStyleSheet("color:#34495E;background:#E7E7E7;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedSeamFinding(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedSeamFinding();
        ui->TaskNull->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->Calibration->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFinding->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
        ui->SeamFindingStart2End->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamTracking->setStyleSheet("color:#34495E;background:#E7E7E7;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedSeamFindingStart2End(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedSeamFindingStart2End();
        ui->TaskNull->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->Calibration->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFinding->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFindingStart2End->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
        ui->SeamTracking->setStyleSheet("color:#34495E;background:#E7E7E7;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedSeamTracking(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedSeamTracking();
        ui->TaskNull->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->Calibration->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFinding->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamFindingStart2End->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->SeamTracking->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalPos1(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalPos1();
        ui->CalPos1->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalPos2(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalPos2();
        ui->CalPos2->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalPos3(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalPos3();
        ui->CalPos3->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalPos4(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalPos4();
        ui->CalPos4->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalPos5(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalPos5();
        ui->CalPos5->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalPos6(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalPos6();
        ui->CalPos6->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
void HmiInstance::onbtnClickedCalibrationDo(){
    if(LocalRemote == LOCALCONTOLLER){
        double tempX,tempY,tempZ,tempA,tempB,tempC;
        this->pbackendinterface->onbtnClickedCalibrationDo(tempX,tempY,tempZ,tempA,tempB,tempC);
        ui->CalibrationSave->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
        ui->H2EX->setValue(tempX);
        ui->H2EY->setValue(tempY);
        ui->H2EZ->setValue(tempZ);
        ui->H2EA->setValue(tempA);
        ui->H2EB->setValue(tempB);
        ui->H2EC->setValue(tempC);
    }
    else{

    }
}

void HmiInstance::onbtnClickedPointRecord(){
    static short Record = 0;
    if(LocalRemote == LOCALCONTOLLER){
        if(Record == 0){
            this->ui->PointRecord->setText("记录中");
            this->pbackendinterface->onbtnClickedPointRecord();
            Record = 1;
        }
        else{
            this->ui->PointRecord->setText("记录");
             this->pbackendinterface->onbtnClickedPointRecord();
             Record = 0;
        }
    }
    else{

    }
}

void HmiInstance::onbtnClickedCalibrationReset(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedCalibrationReset();
        ui->CalPos1->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->CalPos2->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->CalPos3->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->CalPos4->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->CalPos5->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->CalPos6->setStyleSheet("color:#34495E;background:#E7E7E7;");
        ui->CalibrationSave->setStyleSheet("color:#34495E;background:#E7E7E7;");


        ui->H2EX->setValue(0.00);
        ui->H2EY->setValue(0.00);
        ui->H2EZ->setValue(0.00);
        ui->H2EA->setValue(0.00);
        ui->H2EB->setValue(0.00);
        ui->H2EC->setValue(0.00);
    }
    else{

    }
}
void  HmiInstance::onbtnClickedWorkType(){

    if(LocalRemote == LOCALCONTOLLER){
        if(this->mWorkType == ENUM_WorkType::Auto){
            ui->WorkType->setText("当前：手动模式");
            this->pbackendinterface->onbtnClickedWorkType();
            mWorkType = ENUM_WorkType::Mannual;

            this->ui->Calibration->setEnabled(true);
            //this->ui->SeamFinding->setEnabled(true);
            this->ui->SeamFindingStart2End->setEnabled(true);
            //this->ui->SeamTracking->setEnabled(true);

            this->ui->CalPos1->setEnabled(true);
            this->ui->CalPos2->setEnabled(true);
            this->ui->CalPos3->setEnabled(true);
            this->ui->CalPos4->setEnabled(true);
            this->ui->CalPos5->setEnabled(true);
            this->ui->CalPos6->setEnabled(true);
            this->ui->CalibrationDo->setEnabled(true);
            this->ui->CalibrationSave->setEnabled(true);
            this->ui->CalibrationReset->setEnabled(true);


            this->ui->PointRecord->setEnabled(true);
            this->ui->SeamPosCal->setEnabled(true);
            this->ui->SeamPosReset->setEnabled(true);
            this->ui->SeamPosSend->setEnabled(true);
            this->onbtnClickedTaskNull();
        }
        else{
             ui->WorkType->setText("当前：自动模式");
             this->pbackendinterface->onbtnClickedWorkType();
             this->mWorkType = ENUM_WorkType::Auto;

             this->ui->SeamPosReset->setEnabled(true);
             this->ui->CalibrationReset->setEnabled(true);

             this->ui->Calibration->setEnabled(false);
             this->ui->SeamFinding->setEnabled(false);
             this->ui->SeamFindingStart2End->setEnabled(false);
             this->ui->SeamTracking->setEnabled(false);

             this->ui->CalPos1->setEnabled(false);
             this->ui->CalPos2->setEnabled(false);
             this->ui->CalPos3->setEnabled(false);
             this->ui->CalPos4->setEnabled(false);
             this->ui->CalPos5->setEnabled(false);
             this->ui->CalPos6->setEnabled(false);

             this->ui->CalibrationDo->setEnabled(false);
             this->ui->CalibrationSave->setEnabled(false);
             this->ui->PointRecord->setEnabled(false);
             this->ui->SeamPosCal->setEnabled(false);
             this->ui->SeamPosSend->setEnabled(false);
        }

    }
    else{

    }
}
void  HmiInstance::onbtnClickedSeamPosCal(){
    if(LocalRemote == LOCALCONTOLLER){
        double tempStart[6];
        double tempEnd[6];
        this->pbackendinterface->onbtnClickedSeamPosCal(tempStart,tempEnd);

        ui->StartPoxX->setValue(tempStart[0]);
        ui->StartPoxY->setValue(tempStart[1]);
        ui->StartPoxZ->setValue(tempStart[2]);
        ui->StartPoxA->setValue(tempStart[3]);
        ui->StartPoxB->setValue(tempStart[4]);
        ui->StartPoxC->setValue(tempStart[5]);

        ui->EndPoxX->setValue(tempEnd[0]);
        ui->EndPoxY->setValue(tempEnd[1]);
        ui->EndPoxZ->setValue(tempEnd[2]);
        ui->EndPoxA->setValue(tempEnd[3]);
        ui->EndPoxB->setValue(tempEnd[4]);
        ui->EndPoxC->setValue(tempEnd[5]);
    }
    else{

    }
}
void  HmiInstance::onbtnClickedSeamPosReset(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedSeamPosReset();
        ui->StartPoxX->setValue(0.00);
        ui->StartPoxY->setValue(0.00);
        ui->StartPoxZ->setValue(0.00);
        ui->StartPoxA->setValue(0.00);
        ui->StartPoxB->setValue(0.00);
        ui->StartPoxC->setValue(0.00);

        ui->EndPoxX->setValue(0.00);
        ui->EndPoxY->setValue(0.00);
        ui->EndPoxZ->setValue(0.00);
        ui->EndPoxA->setValue(0.00);
        ui->EndPoxB->setValue(0.00);
        ui->EndPoxC->setValue(0.00);
    }
    else{

    }
}
void  HmiInstance::onbtnClickedSeamPosSend(){
    if(LocalRemote == LOCALCONTOLLER){
        this->pbackendinterface->onbtnClickedSeamPosSend();
    }
    else{

    }
}

void HmiInstance::RemoteDataRecv(QByteArray Data){
    if(LocalRemote == LOCALCONTOLLER){

    }
    else{

    }
}

void HmiInstance::RemoteDataSend(QByteArray& Data){
    if(LocalRemote == LOCALCONTOLLER){
        if(this->LocalRemote == LOCALCONTOLLER){
            char tempSend[64];
            QString SendString;
            QXmlStreamWriter stream(&SendString);

            memset(tempSend,'\0',strlen(tempSend));
            stream.writeStartElement("TecController");
                stream.writeAttribute("Tec","KUKAPlugin");

            stream.writeEndElement();
            Data = SendString.toLocal8Bit();
        }
        else{
            QString SendString;
            QXmlStreamWriter stream(&SendString);
            stream.writeStartElement("TecController");
                stream.writeAttribute("Tec","KUKAPlugin");

            stream.writeEndElement();
            Data = SendString.toLocal8Bit();
        }
    }
    else{

    }
}

void HmiInstance::onbtnClickedCalibrationSave(){
    if(LocalRemote == LOCALCONTOLLER){
        double Hand2EyePosition[6];

        Hand2EyePosition[0] = this->ui->H2EX->value();
        Hand2EyePosition[1] = this->ui->H2EY->value();
        Hand2EyePosition[2] = this->ui->H2EZ->value();
        Hand2EyePosition[3] = this->ui->H2EA->value();
        Hand2EyePosition[4] = this->ui->H2EB->value();
        Hand2EyePosition[5] = this->ui->H2EC->value();

        this->ui->H2EX->setValue(Hand2EyePosition[0]);
        this->ui->H2EY->setValue(Hand2EyePosition[1]);
        this->ui->H2EZ->setValue(Hand2EyePosition[2]);
        this->ui->H2EA->setValue(Hand2EyePosition[3]);
        this->ui->H2EB->setValue(Hand2EyePosition[4]);
        this->ui->H2EC->setValue(Hand2EyePosition[5]);

        this->pbackendinterface->onbtnClickedCalibrationSave(Hand2EyePosition);
        ui->CalibrationSave->setStyleSheet("color:#2D3E50;background:#B8C6D1;");
    }
    else{

    }
}
